package com.project.base.common;

import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.net.URLEncoder;


/**
 * 说明：
 *
 * @author yecan
 * @date 2016年7月11日
 */
public class FilenameUtils {
    public static String encodeDownloadFilename(String filename, String agent)
            throws IOException {
        if (agent.contains("Firefox")) {
            filename = "=?UTF-8?B?"
                    + new BASE64Encoder().encode(filename.getBytes("utf-8"))
                    + "?=";
            filename = filename.replaceAll("\r\n", "");
        } else {
            filename = URLEncoder.encode(filename, "utf-8");
            filename = filename.replace("+", " ");
        }
        return filename;
    }

}
